<?php
require_once BASEPATH."application/default/models/Do/News.php";

class News
{
	protected $_doNews;

	protected $_show = 5;

	/** public function __construct() {{{
	 *
	 *
	 */
	public function __construct()
	{
		$this->_doNews = new Do_News();
	}
	/*}}}*/

	/** public function count() {{{
	 *
	 *
	 */
	public function count()
	{
		$db = $this->_doNews->getAdapter()->getConnection();
		$stm = $db->query('SELECT COUNT(*) AS Total FROM tb_news');
		$obj = $stm->fetchObject();

		return $obj->Total;
	}
	/*}}}*/

	/** public function lista() {{{
	 *
	 *
	 */
	public function lista()
	{
		$stm = $this->_doNews->fetchAll(null,'Date');

		return $stm;
	}
	/*}}}*/

	/** public function find($id) {{{
	 *
	 *
	 */
	public function find($id)
	{
		$rowSet = $this->_doNews->find($id);

		return $rowSet->current();
	}
	/*}}}*/

	/** public function getDo() {{{
	 *
	 *
	 */
	public function getDo()
	{
		return $this->_doNews;
	}
	/*}}}*/

	/** public function getFeedAtom() {{{
	 *
	 *
	 */
	public function getFeedAtom()
	{
		return $this->getFeed('atom');
	}
	/*}}}*/

	/** public function getFeedRss() {{{
	 *
	 *
	 */
	public function getFeedRss()
	{
		return $this->getFeed('rss');
	}
	/*}}}*/


	/** protected function getFeed($strFeed) {{{
	 *
	 *
	 */
	protected function getFeed($strFeed)
	{
		$feedArray = array( 'title' 	=> 'PHPMashup - News', 
							'link' 		=> 'http://www.phpmashup.com',
							'charset' 	=> 'UTF-8',
							'author' 	=> 'PHPMashup',
							'email' 	=> 'contato@phpmashup.com',
							'entries' 	=> array()
				      );



		$obj = $this->lista();

		foreach($obj as $val)
		{
			$feedArray['entries'][] = array(
											'title' 		=> $val->title,
											'link'			=> $feedArray['link']."/news/index/show/id/".$val->cd_news,
											'lastUpdated'	=> $val->date,
											'description'	=> $val->description
										   );
		}
		
		$feed = Zend_Feed::importArray($feedArray, $strFeed);

		foreach ($feed as $entry)
		{
			$element = $entry->summary->getDOM();
		}


		return $feed->send();
	}
	/*}}}*/
}
?>
